<template>
  <el-card>
    <template #header>订单信息</template>
    <div>
      <!--  渲染表格数据 -->
      <el-table :data="ordersList" style="width: 100%" size="small">
        <el-table-column prop="sn" label="订单号" width="170"></el-table-column>

        <el-table-column
          prop="create_time"
          label="下单时间"
          width="150"
        ></el-table-column>

        <el-table-column prop="goods_name" label="商品名称"></el-table-column>

        <el-table-column prop="num" label="商品数量"></el-table-column>

        <el-table-column prop="category_name" label="商品分类">
        </el-table-column>

        <el-table-column prop="selling_price" label="订单价格">
        </el-table-column>

        <el-table-column prop="user_name" label="收货人"> </el-table-column>

        <el-table-column prop="user_mobile" label="联系方式"> </el-table-column>

        <el-table-column label="支付方式">
          <template v-slot="{ row }">
            <el-tag type="success" v-if="row.pay_type === 1">微信</el-tag>
            <el-tag v-else>支付宝</el-tag>
          </template>
        </el-table-column>

        <el-table-column prop="address" label="收获地址" width="250">
        </el-table-column>

        <el-table-column label="订单状态">
          <template v-slot="{ row }">
            <el-tag type="danger" v-if="row.status === 0">未付款</el-tag>
            <el-tag type="warning" v-else-if="row.status === 1">待发货</el-tag>
            <el-tag type="success" v-else-if="row.status === 2">已发货</el-tag>
            <el-tag v-else>确认收货</el-tag>
          </template>
        </el-table-column>

        <el-table-column prop="remark" label="备注"></el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </el-card>
</template>

<script>
import { ordersList } from '../../api/orders.js'
export default {
  data() {
    return {
      ordersList: [],
      currentPage: 1,
      total: 0,
      pageSize: 5
    }
  },
  created() {
    this.getOrdersList()
  },
  methods: {
    async getOrdersList() {
      const users = JSON.parse(localStorage.getItem('users') || '{}')
      const { data, count } = await ordersList({
        member_id: users.member_id,
        access_token: users.access_token,
        page: this.currentPage,
        limit: this.pageSize
      })
      this.ordersList = data
      this.total = count
      console.log(data)
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`)
      this.pageSize = val
      this.getOrdersList()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`)
      this.currentPage = val
      this.getOrdersList()
    }
  }
}
</script>

<style lang="less" scoped></style>
